class Solution {
public:
    static bool cmp(const pair<int,int>& a,const pair<int,int>& b){
        if(a.first == b.first) return a.second > b.second;
        return a.first < b.first;
    }
    
    int bestSeqAtIndex(vector<int>& height, vector<int>& weight) {
        int n = height.size();
        vector<pair<int,int> > nums;
        for(int i = 0;i < n;i++){
            nums.push_back({height[i],weight[i]});
        }
        sort(nums.begin(),nums.end(),cmp);
        
        vector<int> dp;
        for(int i = 0;i < n;i++){
            auto p = lower_bound(dp.begin(),dp.end(),nums[i].second);
            
            if(p == dp.end()){
                dp.push_back(nums[i].second);
                cout<<nums[i].second<<endl;
            }else{
                *p = nums[i].second;
            }
        }
        return dp.size();
    }
};
